﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSVExportImport
{
    public class Parameters
    {
        public static readonly string QUOTE = "\"";
        public static readonly string QUOTE_ESCAPE = "\\";
        public static readonly string ITEM_SEPARATOR = ",";
        public static readonly string LINE_SEPARATOR = "\n";

        public static string FormatValue(String value)
        {
            if (value == null) 
                return String.Format("{0}{1}", QUOTE, QUOTE);
            else
                return String.Format("{0}{1}{2}", QUOTE, value.Replace(QUOTE, QUOTE_ESCAPE + QUOTE), QUOTE);
        }
        public static string ParseValue(String value)
        {
            if (value == null)
                return null;

            value = value.Trim();

            if (value.StartsWith(QUOTE))
            {
                return value.Substring(QUOTE.Length, value.Length - 2 * QUOTE.Length).Replace(QUOTE_ESCAPE + QUOTE, QUOTE);
            }
            else
            {
                return value;
            }
        }
        public static string Trim(String value)
        {
            if (value == null)
                return null;
            return value.Trim();
        }

    }
}
